#include "platform.h"
void systemClockConfig(void)
{
    /*预期产生120Mhz的系统时钟；APB1 60Mhz和APB2不分频直出120M;
    流程：8MHZ晶振频率 -> PLLPRESEL选0 -> PREDV0 2 分频得4M
          -> PLLSEL选1 -> PLLMF 30倍频 得120M CK_PLL-> SCS选0b10 ->CK_SYS 出120M
          -> AHB Prescaler不分频得120M CK_AHB ->使能AHB enable 120M进内核
          -> APB1 Prescaler 2分频得最高60MHZ的CK_APB1 -> 使能Peripheral enable
          -> APB2 Prescaler 不分频的最高 120MHZ的 CK_APB2 -> 使能Peripheral enable*/
    int toutCnt = 0;
    rcu_deinit();
    rcu_osci_on(RCU_HXTAL);
    while( !rcu_flag_get(RCU_FLAG_HXTALSTB) && toutCnt<100000000){
        toutCnt++;
    }

    rcu_pllpresel_config(RCU_PLLPRESRC_HXTAL);
    rcu_predv0_config(RCU_PREDV0_DIV2);
    rcu_pll_config(RCU_PLLSRC_HXTAL_IRC48M,RCU_PLL_MUL30);
    rcu_osci_on(RCU_PLL_CK);
    toutCnt = 0;
    while( !rcu_flag_get(RCU_FLAG_PLLSTB) && toutCnt<100000000){
        toutCnt++;
    }


    rcu_system_clock_source_config(RCU_CKSYSSRC_PLL);
    rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
    rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV2);
    rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1);

    SystemCoreClockUpdate();

}
